﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JTLeigh.Commerce.Spencer.Features.ProductFeedback.Business.UnitTests
{

	/// <summary>
	/// Unit tests for the <see cref="AveragingCounter"/> class.
	/// </summary>
	[TestClass]
	public class AveragingCounterFixture
	{

		#region Methods

		/// <summary>
		/// Tests all methods and properties of the counter.
		/// </summary>
		[TestMethod]
		public void TestAveragingCounterOperation()
		{
			AveragingCounter counter;

			counter = new AveragingCounter();
			Assert.AreEqual(0, counter.Sum);
			Assert.AreEqual(0, counter.Count);
			Assert.IsNull(counter.Average);

			counter.AddValue(1);
			Assert.AreEqual(1, counter.Sum);
			Assert.AreEqual(1.0d, counter.Average);

			counter.AddValue(2);
			Assert.AreEqual(3, counter.Sum);
			Assert.AreEqual(1.5d, counter.Average);

			counter.AddValue(1);
			Assert.AreEqual(4, counter.Sum);
			Assert.AreEqual(1.33d, Math.Round(counter.Average.Value, 2));

			counter.Reset();
			Assert.AreEqual(0, counter.Sum);
			Assert.AreEqual(0, counter.Count);
			Assert.IsNull(counter.Average);
		}

		#endregion // Methods

	}

}
